<?php
// +----------------------------------------------------------------------
//            -------------------------
//           /   / ----------------\  \
//          /   /             \  \
//         /   /              /  /
//        /   /    /-------------- /  /
//       /   /    /-------------------\  \
//      /   /                   \  \
//     /   /                     \  \
//    /   /                      /  /
//   /   /      /----------------------- /  /
//  /-----/      /---------------------------/
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://baimifan.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 汪利东,2016-04-12 10:33
// +----------------------------------------------------------------------

namespace Admin\Controller;


class RefundListController extends BaseController
{
    public function index()
    {
        $map = [];
        $refund_id = I('get.refund_id');
        if (!empty($refund_id)) {
            $map['a.refund_id'] = $refund_id;
        }
        $keywords = I('get.keywords');
        if (!empty($keywords)) {
            $map['a.refund_id'] = $keywords;
//            $map['_logic'] = 'OR';
        }
        $interval_time = I('get.interval_time');
        if (!empty($interval_time)) {
            $time=explode('~',$interval_time);
            $time[0]=$time[0].' 00:00:00';
            $time[1]=$time[1].' 23:59:59';
            $map['a.create_time'] = [
                ['gt',$time[0]],
                ['lt',$time[1]]
            ];
        }
        $type = I('get.type');
        switch($type){
            case '1':
            case '2':
            case '3':$map['a.type'] = $type;break;
            default:break;
        }
        $count = D('Refund')->alias('a')->where($map)->count();// 查询满足要求的总记录数
        $Page = new  \Admin\Common\Page($count, C('page.size'));// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $where['keywords'] = $keywords;
        $where['interval_time'] = $interval_time;
        $where['type'] = $type;
        foreach ($where as $key => $val) {
            $Page->parameter[$key] = $val;
        }
        $show = $Page->show();// 分页显示输出
        $this->assign('page', $show);// 赋值分页输出


        $data = D('Refund')->alias('a')
            ->where($map)
            ->limit($Page->firstRow . ',' . $Page->listRows)
            ->order('a.refund_id desc')
            ->select();
        if(I("get.execl")==1){
            $data = D('Refund')->alias('a')
                ->where($map)
                ->order('a.refund_id desc')
                ->select();
            $file = excel_export($data);
            ouput_Browser($file);
        }else{
            $this->data = $data;
            $this->display();
        }
    }
}